package com.ruyuan.ingestion.parser.hbase;
import com.ruyuan.ingestion.parser.UserParser;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
public class HBaseUserParser extends UserParser<Put> {

    /**
     * 解析数据封装为一个put实例
     * */
    @Override
    public Put parse(String[] fields) {
        /**
         * ColumnFamily1: profile 包含 birthyear,gender
         * ColumnFamily2: region 包含 locale  timezone location
         * ColumnFamily3: regisration 包含 joinedAt
         * */

        //fields：user_id,locale,birthyear,gender,joinedAt,location,timezone
        //user_id
        Put put = new Put(Bytes.toBytes(fields[0]));

        //profile:birthyear,gender
        put = put.addColumn(Bytes.toBytes("profile"),Bytes.toBytes("birthyear"),Bytes.toBytes(fields[2]));
        put = put.addColumn(Bytes.toBytes("profile"),Bytes.toBytes("gender"),Bytes.toBytes(fields[3]));

        //region：locale
        put = put.addColumn(Bytes.toBytes("region"),Bytes.toBytes("locale"),Bytes.toBytes(fields[1]));
        put = put.addColumn(Bytes.toBytes("region"),Bytes.toBytes("location"),Bytes.toBytes(fields[5]));
        put = put.addColumn(Bytes.toBytes("region"),Bytes.toBytes("timezone"),Bytes.toBytes(fields[6]));
        //registration
        put = put.addColumn(Bytes.toBytes("registration"),Bytes.toBytes("joinedAt"),Bytes.toBytes(fields[4]));
        return put;
    }
}
